package com.guigu.lc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.common.mapper.SysMenusMapper;
import com.guigu.common.pojo.SysMenus;
import com.guigu.lc.serach.MenusSerach;
import com.guigu.lc.service.sys_MenusService;
import com.guigu.lc.view.Menuanduserview;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 动态菜单Service实现类
 */
@Service
public class sys_MenusServiceimpl implements sys_MenusService {

    //菜单的Mapper
    @Resource
    private SysMenusMapper sysMenusMapper;



    @Override
    public Map<String, Map<String, List<SysMenus>>> querymapmenusService(String userid) {
        Map<String,Map<String,List<SysMenus>>> Map = new LinkedHashMap<String,Map<String,List<SysMenus>>>();
        List<SysMenus> sysMenus = this.sysMenusMapper.querymapmenus(userid);
        for(int i=0; i<sysMenus.size(); i++){
            SysMenus p1 = sysMenus.get(i);
            if(p1.getParentId()==0){
                Map<String,List<SysMenus>> menuMap = new LinkedHashMap<String,List<SysMenus>>();
                for(int j=0;j<sysMenus.size();j++){
                    SysMenus p2 = sysMenus.get(j);
                    List<SysMenus> menus = new ArrayList<SysMenus>();
                    if(p1.getId()==p2.getParentId()){
                        for(int z=0;z<sysMenus.size();z++){
                            SysMenus p3 = sysMenus.get(z);
                            if(p2.getId()==p3.getParentId()){
                                menus.add(p3);
                            }
                        }
                        menuMap.put(p2.getName(),menus);
                    }
                    Map.put(p1.getName(),menuMap);
                }
            }
        }
        return Map;
    }

    @Override
    public MenusSerach queryAllMenusService(MenusSerach menusSerach) {
        PageHelper.startPage(menusSerach.getPageNumber(),menusSerach.getPageSize());
        PageInfo page=new PageInfo(this.sysMenusMapper.queryallemnussys(menusSerach));
        MenusSerach serach=new MenusSerach();
        serach.setRows(page.getList());
        serach.setTotal(page.getTotal());
        return serach;
    }

}
